package com.ljx.itbbs.server.mall.domain.enums;

import com.ljx.itbbs.server.article.domain.entity.ResourceEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-03-28  20:32
 */
@Getter
@AllArgsConstructor
public enum OrderTypeEnum {

    GOODS(1, "商品"),
    ARTICLE_RESOURCE(2, "文章资源"),
    RECHARGE(3, "充值");

    private Integer type;
    private String desc;
    private static Map<Integer, OrderTypeEnum> cache;

    static {
        cache = Arrays.stream(OrderTypeEnum.values()).collect(Collectors.toMap(OrderTypeEnum::getType, Function.identity()));
    }

    public static OrderTypeEnum of(Integer type) {
        return cache.get(type);
    }

    public static String getObjId(Long resourceId, OrderTypeEnum orderTypeEnum) {
        return orderTypeEnum.getType() + "_" + resourceId;
    }

    public static Long getTrueObjId(String objIdStr, Integer type) {
        return Long.parseLong(objIdStr.replace(type + "_", ""));
    }

}
